From 5814abdc79100050f099b339df5f0e8bfc38052a Mon Sep 17 00:00:00 2001 From: Gianni Tedesco Date: Wed, 4 Aug 2010 14:24:43 +0100 Subject: [PATCH] xl: prevent attempts to remove non-attached pci pass-through devices Signed-off-by: Gianni Tedesco Signed-off-by: Stefano Stabellini --- tools/libxl/libxl_pci.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/libxl/libxl_pci.c b/tools/libxl/libxl_pci.c index e74a3f1ade..4fc4727b80 100644 --- a/tools/libxl/libxl_pci.c +++ b/tools/libxl/libxl_pci.c @@ -564,12 +564,20 @@ int libxl_device_pci_add(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcide int libxl_device_pci_remove(libxl_ctx *ctx, uint32_t domid, libxl_device_pci *pcidev) { + libxl_device_pci *assigned; char *path; char *state; - int hvm, rc; + int hvm, rc, num; int stubdomid = 0; - /* TODO: check if the device can be detached */ + if ( !libxl_device_pci_list_assigned(ctx, &assigned, domid, &num) ) { + if ( !is_assigned(assigned, num, pcidev->domain, + pcidev->bus, pcidev->dev, pcidev->func) ) { + XL_LOG(ctx, XL_LOG_ERROR, "PCI device not attached to this domain"); + return ERROR_INVAL; + } + } + libxl_device_pci_remove_xenstore(ctx, domid, pcidev); hvm = is_hvm(ctx, domid); -- 2.30.2